/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ebdesk.view.dhkp;

import com.ebdesk.controller.dhkp.DHKP;
import com.ebdesk.controller.dhkp.DHKPTableModel;
import com.ebdesk.controller.dhkp.Print;
import com.ebdesk.view.MainFrame;
import java.awt.Rectangle;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.SwingWorker;


/**
 *
 * @author mbenk
 */
public class DHKPInternalFrame extends javax.swing.JInternalFrame {
    private Object[][] dataVector; 
    private Object[] dataKec;
    private Object[] dataKel;
    private Object[] dataBuku;
    private Object[] dataPrinter;
    private String header[] = new String[6];
    
    private int firstRecord = 0;
    private int totalRow = 0;
    private boolean clickedSearch = false;
    private Pattern p = Pattern.compile("\\d+");

    private StringBuilder cb = new StringBuilder();
    private StringBuilder cb2 = new StringBuilder(); 
    
    private DHKP dhkp;
    private Print pt;
    private PrintDialog pd;
    private ProgressDialog plog;
    private MainFrame mf;
    
    /**
     * Creates new form DHKPInternalFrame
     */
    public DHKPInternalFrame(MainFrame mainFrame) {
        try{
            dhkp = new DHKP();
            mf = mainFrame;
                   
            pt = new Print();
            pd = new PrintDialog(mf,true);
            plog = new ProgressDialog(mf,true);
            
            header[0] = "NOP";
            header[1] = "Nama Wajib Pajak";
            header[2] = "Alamat Wajib Pajak";
            header[3] = "Alamat Objek Pajak"; 
            header[4] = "Pajak Terhutang";
            header[5] = "Tgl Terbit";

            cb.setLength(0);
            cb2.setLength(0);

            cb.append("select count(*) from pbb.view_sppt");
            cb2.append("select * from pbb.view_sppt "
                    + "order by pbb.view_sppt.nop "
                    + "limit (select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'paging')::integer");

            totalRow = Integer.parseInt(dhkp.getQuery(cb.toString()).toString());
            dataKec = dhkp.getDataCB(1);
            dataBuku = dhkp.getDataCB(3);
            dataPrinter = dhkp.getPrinter();
        
            initComponents();
        }  
        catch(Exception e){
            e.printStackTrace();
        }
        
  
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        TfNOP = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        ComboBoxKecamatan = new javax.swing.JComboBox();
        ComboBoxKelurahan = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        TfNama = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        TfUrutDari = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        TfUrutSampai = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        TfTahun = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        ComboBoxBuku = new javax.swing.JComboBox();
        SearchButton = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        TfBlok = new javax.swing.JTextField();
        ScrollPane = new javax.swing.JScrollPane();
        TabelDHKP = new javax.swing.JTable(new DHKPTableModel(dataVector, header));
        SelectRowPanel = new javax.swing.JPanel();
        SelectRowLabel = new javax.swing.JLabel();
        SelectPagePanel = new javax.swing.JPanel();
        SelectPageLabel = new javax.swing.JLabel();
        ToolBar = new javax.swing.JToolBar();
        FirstBlockButton = new javax.swing.JButton();
        PreviousBlockButton = new javax.swing.JButton();
        PreviousRowButton = new javax.swing.JButton();
        NextRowButton = new javax.swing.JButton();
        NextBlockButton = new javax.swing.JButton();
        LastBlockButton = new javax.swing.JButton();
        ComboBoxPrint = new javax.swing.JComboBox();
        PrintButton = new javax.swing.JButton();
        ProgressBarSearch = new javax.swing.JProgressBar();

        setTitle("DHKP");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Searching", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(51, 102, 255)));

        jLabel1.setText("Kecamatan:");

        TfNOP.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TfNOPKeyPressed(evt);
            }
        });

        jLabel2.setText("Kelurahan:");

        ComboBoxKecamatan.setModel(new javax.swing.DefaultComboBoxModel(dataKec));
        ComboBoxKecamatan.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                ComboBoxKecamatanItemStateChanged(evt);
            }
        });

        ComboBoxKelurahan.setModel(new javax.swing.DefaultComboBoxModel(new String[] {""}));
        ComboBoxKelurahan.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                ComboBoxKelurahanItemStateChanged(evt);
            }
        });

        jLabel3.setText("NOP:");

        jLabel4.setText("Nama:");

        TfNama.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TfNamaKeyPressed(evt);
            }
        });

        jLabel5.setText("No. Urut");

        TfUrutDari.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TfUrutDariKeyPressed(evt);
            }
        });

        jLabel6.setText("s/d");

        TfUrutSampai.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TfUrutSampaiKeyPressed(evt);
            }
        });

        jLabel7.setText("Tahun");

        TfTahun.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TfTahunKeyPressed(evt);
            }
        });

        jLabel8.setText("Buku");

        ComboBoxBuku.setModel(new javax.swing.DefaultComboBoxModel(dataBuku));
        ComboBoxBuku.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                ComboBoxBukuItemStateChanged(evt);
            }
        });

        SearchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ebdesk/view/images/search.gif"))); // NOI18N
        SearchButton.setEnabled(false);
        SearchButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                SearchButtonMouseClicked(evt);
            }
        });

        jLabel9.setText("Blok:");

        TfBlok.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TfBlokKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ComboBoxKecamatan, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ComboBoxKelurahan, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TfNOP, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TfNama, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TfBlok, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(TfUrutDari, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(TfUrutSampai, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(TfTahun, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ComboBoxBuku, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(SearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(SearchButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(TfNOP)
                        .addComponent(jLabel2)
                        .addComponent(ComboBoxKecamatan)
                        .addComponent(ComboBoxKelurahan)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4)
                        .addComponent(TfNama)
                        .addComponent(jLabel5)
                        .addComponent(TfUrutDari)
                        .addComponent(jLabel6)
                        .addComponent(TfUrutSampai)
                        .addComponent(jLabel7)
                        .addComponent(TfTahun)
                        .addComponent(jLabel8)
                        .addComponent(ComboBoxBuku)
                        .addComponent(jLabel9)
                        .addComponent(TfBlok, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        TabelDHKP.setModel(new DHKPTableModel(new Object[][] {
            {"Loading..", "Loading..", "Loading..", "Loading..", "Loading..",
                "Loading.."}},header)
    );
    TabelDHKP.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            TabelDHKPMouseClicked(evt);
        }
    });
    ScrollPane.setViewportView(TabelDHKP);

    SelectRowPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

    javax.swing.GroupLayout SelectRowPanelLayout = new javax.swing.GroupLayout(SelectRowPanel);
    SelectRowPanel.setLayout(SelectRowPanelLayout);
    SelectRowPanelLayout.setHorizontalGroup(
        SelectRowPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(SelectRowLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
    );
    SelectRowPanelLayout.setVerticalGroup(
        SelectRowPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(SelectRowPanelLayout.createSequentialGroup()
            .addComponent(SelectRowLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(0, 0, Short.MAX_VALUE))
    );

    try{
        TabelDHKP.getSelectionModel().setSelectionInterval(0, 0);
        double Block = Double.parseDouble(dhkp.getQuery("select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'paging'").toString());
        SelectRowLabel.setText("Row: "+(firstRecord+TabelDHKP.getSelectedRow()+1)+" of "+dhkp.getQuery("select count(*) from pbb.view_sppt").toString());
        SelectPageLabel.setText("Page: "+ (int)(firstRecord/Block+1)+" of "+ (int)Math.ceil(totalRow/Block));
        ProgressBarSearch.setVisible(false);
    }
    catch(Exception e){
        e.printStackTrace();
    }

    SelectPagePanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

    javax.swing.GroupLayout SelectPagePanelLayout = new javax.swing.GroupLayout(SelectPagePanel);
    SelectPagePanel.setLayout(SelectPagePanelLayout);
    SelectPagePanelLayout.setHorizontalGroup(
        SelectPagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(SelectPagePanelLayout.createSequentialGroup()
            .addComponent(SelectPageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(0, 0, Short.MAX_VALUE))
    );
    SelectPagePanelLayout.setVerticalGroup(
        SelectPagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(SelectPageLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );

    ToolBar.setFloatable(false);
    ToolBar.setRollover(true);
    ToolBar.setBorderPainted(false);

    FirstBlockButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ebdesk/view/images/first.png"))); // NOI18N
    FirstBlockButton.setEnabled(false);
    FirstBlockButton.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            FirstBlockButtonMouseClicked(evt);
        }
    });
    ToolBar.add(FirstBlockButton);

    PreviousBlockButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ebdesk/view/images/rewind.png"))); // NOI18N
    PreviousBlockButton.setEnabled(false);
    PreviousBlockButton.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            PreviousBlockButtonMouseClicked(evt);
        }
    });
    ToolBar.add(PreviousBlockButton);

    PreviousRowButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ebdesk/view/images/left.png"))); // NOI18N
    PreviousRowButton.setEnabled(false);
    PreviousRowButton.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            PreviousRowButtonMouseClicked(evt);
        }
    });
    ToolBar.add(PreviousRowButton);

    NextRowButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ebdesk/view/images/right.png"))); // NOI18N
    NextRowButton.setEnabled(false);
    NextRowButton.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            NextRowButtonMouseClicked(evt);
        }
    });
    ToolBar.add(NextRowButton);

    NextBlockButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ebdesk/view/images/forward.png"))); // NOI18N
    NextBlockButton.setEnabled(false);
    NextBlockButton.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            NextBlockButtonMouseClicked(evt);
        }
    });
    ToolBar.add(NextBlockButton);

    LastBlockButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ebdesk/view/images/last.png"))); // NOI18N
    LastBlockButton.setEnabled(false);
    LastBlockButton.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            LastBlockButtonMouseClicked(evt);
        }
    });
    ToolBar.add(LastBlockButton);

    ComboBoxPrint.setModel(new javax.swing.DefaultComboBoxModel(dataPrinter));
    ComboBoxPrint.setMaximumSize(new java.awt.Dimension(200, 20));
    ComboBoxPrint.setMinimumSize(new java.awt.Dimension(150, 25));
    ComboBoxPrint.setPreferredSize(new java.awt.Dimension(150, 15));
    ToolBar.add(ComboBoxPrint);

    PrintButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ebdesk/view/images/print.gif"))); // NOI18N
    PrintButton.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    PrintButton.setEnabled(false);
    PrintButton.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            PrintButtonMouseClicked(evt);
        }
    });
    ToolBar.add(PrintButton);

    ProgressBarSearch.setMaximumSize(new java.awt.Dimension(200, 20));
    ProgressBarSearch.setMinimumSize(new java.awt.Dimension(150, 25));
    ProgressBarSearch.setPreferredSize(new java.awt.Dimension(150, 15));
    ProgressBarSearch.setStringPainted(true);
    ToolBar.add(ProgressBarSearch);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(ToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 581, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE))
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(ScrollPane, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(SelectRowPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(SelectPagePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addContainerGap())))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(ScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(SelectRowPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(SelectPagePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(ToolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TfNOPKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TfNOPKeyPressed
        // TODO add your handling code here:
        int input = evt.getKeyChar();
        int inputBspace = evt.getKeyCode();
        if ((input >= '0' && input <= '9') || (inputBspace == evt.VK_BACK_SPACE) || (inputBspace == evt.VK_DELETE)||(inputBspace == evt.VK_LEFT) || (inputBspace == evt.VK_RIGHT)) {
            TfNOP.setEditable(true);
            clickedSearch = false;
        } else {
            TfNOP.setEditable(false);
        }
    }//GEN-LAST:event_TfNOPKeyPressed

    private void ComboBoxKecamatanItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_ComboBoxKecamatanItemStateChanged
        // TODO add your handling code here:
        try {
            dataKel = dhkp.getDataCB(2, evt.getItem().toString().substring(6));
            getComboBoxKelurahan().setModel(new javax.swing.DefaultComboBoxModel(dataKel));
            clickedSearch = false;
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }//GEN-LAST:event_ComboBoxKecamatanItemStateChanged

    private void ComboBoxKelurahanItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_ComboBoxKelurahanItemStateChanged
        // TODO add your handling code here:
        clickedSearch = false;
    }//GEN-LAST:event_ComboBoxKelurahanItemStateChanged

    private void TfNamaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TfNamaKeyPressed
        // TODO add your handling code here:
        int input = evt.getKeyChar();
        int inputBspace = evt.getKeyCode();
        if ((input >= 'A' && input <= 'Z') || (input >= 'a' && input <= 'z') || (inputBspace == evt.VK_BACK_SPACE) || (inputBspace == evt.VK_DELETE) || (inputBspace == evt.VK_SPACE)||(inputBspace == evt.VK_LEFT) || (inputBspace == evt.VK_RIGHT)) {
            TfNama.setEditable(true);
            clickedSearch = false;

        } else {
            TfNama.setEditable(false);
        }
    }//GEN-LAST:event_TfNamaKeyPressed

    private void TfUrutDariKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TfUrutDariKeyPressed
        // TODO add your handling code here:
        int input = evt.getKeyChar();
        int inputBspace = evt.getKeyCode();
        if ((input >= '0' && input <= '9') || (inputBspace == evt.VK_BACK_SPACE) || (inputBspace == evt.VK_DELETE)||(inputBspace == evt.VK_LEFT) || (inputBspace == evt.VK_RIGHT)) {
            TfUrutDari.setEditable(true);
            clickedSearch = false;

        } else {
            TfUrutDari.setEditable(false);
        }
    }//GEN-LAST:event_TfUrutDariKeyPressed

    private void TfUrutSampaiKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TfUrutSampaiKeyPressed
        // TODO add your handling code here:
        int input = evt.getKeyChar();
        int inputBspace = evt.getKeyCode();
        if ((input >= '0' && input <= '9') || (inputBspace == evt.VK_BACK_SPACE) || (inputBspace == evt.VK_DELETE)||(inputBspace == evt.VK_LEFT) || (inputBspace == evt.VK_RIGHT)) {
            TfUrutSampai.setEditable(true);
            clickedSearch = false;

        } else {
            TfUrutSampai.setEditable(false);
        }
    }//GEN-LAST:event_TfUrutSampaiKeyPressed

    private void TfTahunKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TfTahunKeyPressed
        // TODO add your handling code here:
        int input = evt.getKeyChar();
        int inputBspace = evt.getKeyCode();
        if ((input >= '0' && input <= '9') || (inputBspace == evt.VK_BACK_SPACE) || (inputBspace == evt.VK_DELETE)||(inputBspace == evt.VK_LEFT) || (inputBspace == evt.VK_RIGHT)) {
            getTfTahun().setEditable(true);
            clickedSearch = false;
        } else {
            getTfTahun().setEditable(false);
        }
    }//GEN-LAST:event_TfTahunKeyPressed

    private void ComboBoxBukuItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_ComboBoxBukuItemStateChanged
        // TODO add your handling code here:
        clickedSearch = false;
    }//GEN-LAST:event_ComboBoxBukuItemStateChanged

    private void SearchButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SearchButtonMouseClicked
        // TODO add your handling code here:
        if (!SearchButton.isEnabled()) {
            return;
        }
        SearchButton.setEnabled(false);
        FirstBlockButton.setEnabled(false);
        PreviousBlockButton.setEnabled(false);
        PreviousRowButton.setEnabled(false);
        NextRowButton.setEnabled(false);
        NextBlockButton.setEnabled(false);
        LastBlockButton.setEnabled(false);

        SwingWorker search = new SwingWorker<Object[][], Void>() {

            @Override
            public Object[][] doInBackground() {
                try {
                    doSearch();
                    if (Thread.interrupted()) {
                        throw new InterruptedException();
                    }
                    totalRow = Integer.parseInt(dhkp.getQuery(cb.toString()).toString());
                    //Set data yang ditampilkan
                    int Block = Integer.parseInt(dhkp.getQuery("select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'paging'").toString());
                    cb2.append(" order by nop ").append(" limit ").append(Block);
                    dataVector = dhkp.getData(cb2.toString());
                } catch (InterruptedException e) {
                }
                return dataVector;
            }

            @Override
            public void done() {
                try {
                    getTabelDHKP().setModel(new DHKPTableModel(get(), header));
                } catch (InterruptedException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ExecutionException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                getTabelDHKP().getSelectionModel().setSelectionInterval(0, 0);
                firstRecord = 0;

                if (totalRow != 0) {
                    double Block = Double.parseDouble(dhkp.getQuery("select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'paging'").toString());
                    SelectRowLabel.setText("Row: " + (firstRecord + getTabelDHKP().getSelectedRow() + 1) + " of " + totalRow);
                    SelectPageLabel.setText("Page: "+ (int)(firstRecord/Block+1)+" of "+ (int)Math.ceil(totalRow/Block));
                } else {
                    SelectRowLabel.setText("Row: 0 of 0");
                }
                clickedSearch = true;
                hidePB(ProgressBarSearch);
                SearchButton.setEnabled(true);
                FirstBlockButton.setEnabled(true);
                PreviousBlockButton.setEnabled(true);
                PreviousRowButton.setEnabled(true);
                NextRowButton.setEnabled(true);
                NextBlockButton.setEnabled(true);
                LastBlockButton.setEnabled(true);

                if (TfUrutDari.getText().trim().equals("") ^ TfUrutSampai.getText().trim().equals("")) {
                    JOptionPane.showMessageDialog(rootPane, "No urut tidak dijadikan filter karena salah satu field kosong!!!", "Warning", JOptionPane.WARNING_MESSAGE);
                }
            }
        };
        search.execute();
        getTabelDHKP().setModel(new DHKPTableModel(new Object[][]{
                    {"Loading..", "Loading..", "Loading..", "Loading..", "Loading..",
                        "Loading.."}}, header));
        showPB(ProgressBarSearch);

    }//GEN-LAST:event_SearchButtonMouseClicked

    private void TfBlokKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TfBlokKeyPressed
        // TODO add your handling code here:
        int input = evt.getKeyChar();
        int inputBspace = evt.getKeyCode();
        if ((input >= '0' && input <= '9') || (inputBspace == evt.VK_BACK_SPACE) || (inputBspace == evt.VK_DELETE)) {
            TfBlok.setEditable(true);
            clickedSearch = false;

        } else {
            TfBlok.setEditable(false);
        }

    }//GEN-LAST:event_TfBlokKeyPressed

    private void TabelDHKPMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TabelDHKPMouseClicked
        // TODO add your handling code here:
        SelectRowLabel.setText(SelectRowLabel.getText().replaceAll("Row: \\d+ of \\d+", "Row: " + (firstRecord + getTabelDHKP().getSelectedRow() + 1) + " of " + totalRow));
    }//GEN-LAST:event_TabelDHKPMouseClicked

    private void FirstBlockButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_FirstBlockButtonMouseClicked
        if (!FirstBlockButton.isEnabled()) {
            return;
        }
        SearchButton.setEnabled(false);
        FirstBlockButton.setEnabled(false);
        PreviousBlockButton.setEnabled(false);
        PreviousRowButton.setEnabled(false);
        NextRowButton.setEnabled(false);
        NextBlockButton.setEnabled(false);
        LastBlockButton.setEnabled(false);

        SwingWorker block = new SwingWorker<Object[][], Void>() {

            double Block;

            @Override
            public Object[][] doInBackground() {
                try {
                    Block = Double.parseDouble(dhkp.getQuery("select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'paging'").toString());
                    firstRecord = 0;

                    //Sudah pernah di filter
                    if (cb2.toString().contains("limit")) {
                        cb2.replace(cb2.indexOf("limit"), cb2.length(), "limit " + Block + " offset " + firstRecord);
                    } else {
                        cb2.append(" limit ").append(Block);
                    }

                    dataVector = dhkp.getData(cb2.toString());
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
                return dataVector;
            }

            @Override
            public void done() {
                try {
                    getTabelDHKP().setModel(new DHKPTableModel(get(), header));
                } catch (InterruptedException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ExecutionException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }

                getTabelDHKP().getSelectionModel().addSelectionInterval(0, 0);
                SelectRowLabel.setText("Row: " + (firstRecord + getTabelDHKP().getSelectedRow() + 1) + " of " + totalRow);
                SelectPageLabel.setText("Page: "+ (int)(firstRecord/Block+1)+" of "+ (int)Math.ceil(totalRow/Block));

                hidePB(ProgressBarSearch);
                SearchButton.setEnabled(true);
                FirstBlockButton.setEnabled(true);
                PreviousBlockButton.setEnabled(true);
                PreviousRowButton.setEnabled(true);
                NextRowButton.setEnabled(true);
                NextBlockButton.setEnabled(true);
                LastBlockButton.setEnabled(true);
            }
        };
        block.execute();
        getTabelDHKP().setModel(new DHKPTableModel(new Object[][]{
                    {"Loading..", "Loading..", "Loading..", "Loading..", "Loading..",
                        "Loading.."}}, header));

        showPB(ProgressBarSearch);

    }//GEN-LAST:event_FirstBlockButtonMouseClicked

    private void PreviousBlockButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PreviousBlockButtonMouseClicked
        if (!PreviousBlockButton.isEnabled()) {
            return;
        }
        SearchButton.setEnabled(false);
        FirstBlockButton.setEnabled(false);
        PreviousBlockButton.setEnabled(false);
        PreviousRowButton.setEnabled(false);
        NextRowButton.setEnabled(false);
        NextBlockButton.setEnabled(false);
        LastBlockButton.setEnabled(false);

        SwingWorker block = new SwingWorker<Object[][], Void>() {

            double Block;

            @Override
            public Object[][] doInBackground() {
                try {
                    Block = Double.parseDouble(dhkp.getQuery("select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'paging'").toString());
                    if ((firstRecord - Block) >= 0) {
                        firstRecord -= Block;

                        //Sudah pernah di filter
                        if (cb2.toString().contains("limit")) {
                            cb2.replace(cb2.indexOf("limit"), cb2.length(), "limit " + Block + " offset " + firstRecord);
                        } else {
                            cb2.append(" limit ").append(Block);
                        }

                        dataVector = dhkp.getData(cb2.toString());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
                return dataVector;
            }

            @Override
            public void done() {
                try {
                    getTabelDHKP().setModel(new DHKPTableModel(get(), header));
                } catch (InterruptedException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ExecutionException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }

                getTabelDHKP().getSelectionModel().addSelectionInterval(0, 0);
                SelectRowLabel.setText("Row: " + (firstRecord + getTabelDHKP().getSelectedRow() + 1) + " of " + totalRow);
                SelectPageLabel.setText("Page: "+ (int)(firstRecord/Block+1)+" of "+ (int)Math.ceil(totalRow/Block));
                hidePB(ProgressBarSearch);
                SearchButton.setEnabled(true);
                FirstBlockButton.setEnabled(true);
                PreviousBlockButton.setEnabled(true);
                PreviousRowButton.setEnabled(true);
                NextRowButton.setEnabled(true);
                NextBlockButton.setEnabled(true);
                LastBlockButton.setEnabled(true);
            }
        };
        block.execute();
        getTabelDHKP().setModel(new DHKPTableModel(new Object[][]{
                    {"Loading..", "Loading..", "Loading..", "Loading..", "Loading..",
                        "Loading.."}}, header));

        showPB(ProgressBarSearch);

    }//GEN-LAST:event_PreviousBlockButtonMouseClicked

    private void PreviousRowButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PreviousRowButtonMouseClicked
        if (!PreviousRowButton.isEnabled()) {
            return;
        }
        int row = getTabelDHKP().getSelectedRow();

        if (row - 1 < 0) {
            row = 0;
            if (firstRecord > 0) {
                this.PreviousBlockButtonMouseClicked(evt);
            }
        } else {
            row--;
        }
        getTabelDHKP().changeSelection(row, 1, false, false);
        getTabelDHKP().getSelectionModel().addSelectionInterval(row, row);
        getTabelDHKP().scrollRectToVisible(new Rectangle(getTabelDHKP().getCellRect(row, 0, true)));
        SelectRowLabel.setText(SelectRowLabel.getText().replaceAll("Row: \\d+ of \\d+", "Row: " + (firstRecord + getTabelDHKP().getSelectedRow() + 1) + " of " + totalRow));
    }//GEN-LAST:event_PreviousRowButtonMouseClicked

    private void NextRowButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_NextRowButtonMouseClicked
        if (!NextRowButton.isEnabled()) {
            return;
        }
        try {
            int rows = Integer.parseInt(dhkp.getQuery("select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'paging'").toString());
            int row = getTabelDHKP().getSelectedRow();
            if (row + 2 > rows) {
                row = rows - 1;
                this.NextBlockButtonMouseClicked(evt);
            } else {
                if (firstRecord + getTabelDHKP().getSelectedRow() + 1 < totalRow) {
                    row++;
                }
            }
            getTabelDHKP().changeSelection(row, 1, false, false);
            getTabelDHKP().getSelectionModel().addSelectionInterval(row, row);
            getTabelDHKP().scrollRectToVisible(new Rectangle(getTabelDHKP().getCellRect(row, 0, true)));
            SelectRowLabel.setText(SelectRowLabel.getText().replaceAll("Row: \\d+ of \\d+", "Row: " + (firstRecord + getTabelDHKP().getSelectedRow() + 1) + " of " + totalRow));
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }//GEN-LAST:event_NextRowButtonMouseClicked

    private void NextBlockButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_NextBlockButtonMouseClicked
        if (!NextBlockButton.isEnabled()) {
            return;
        }
        SearchButton.setEnabled(false);
        FirstBlockButton.setEnabled(false);
        PreviousBlockButton.setEnabled(false);
        PreviousRowButton.setEnabled(false);
        NextRowButton.setEnabled(false);
        NextBlockButton.setEnabled(false);
        LastBlockButton.setEnabled(false);

        SwingWorker block = new SwingWorker<Object[][], Void>() {

            double Block;

            @Override
            public Object[][] doInBackground() {
                try {
                    Block = Double.parseDouble(dhkp.getQuery("select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'paging'").toString());
                    if ((firstRecord + Block) < totalRow) {
                        firstRecord += Block;

                        //Sudah pernah di filter
                        if (cb2.toString().contains("limit")) {
                            cb2.replace(cb2.indexOf("limit"), cb2.length(), "limit " + Block + " offset " + firstRecord);
                        } else {
                            cb2.append(" limit ").append(Block);
                        }
                        dataVector = dhkp.getData(cb2.toString());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
                return dataVector;
            }

            @Override
            public void done() {
                try {
                    getTabelDHKP().setModel(new DHKPTableModel(get(), header));
                } catch (InterruptedException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ExecutionException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }

                getTabelDHKP().getSelectionModel().addSelectionInterval(0, 0);
                SelectRowLabel.setText("Row: " + (firstRecord + getTabelDHKP().getSelectedRow() + 1) + " of " + totalRow);
                SelectPageLabel.setText("Page: "+ (int)(firstRecord/Block+1)+" of "+ (int)Math.ceil(totalRow/Block));
                hidePB(ProgressBarSearch);
                SearchButton.setEnabled(true);
                FirstBlockButton.setEnabled(true);
                PreviousBlockButton.setEnabled(true);
                PreviousRowButton.setEnabled(true);
                NextRowButton.setEnabled(true);
                NextBlockButton.setEnabled(true);
                LastBlockButton.setEnabled(true);
            }
        };
        block.execute();
        getTabelDHKP().setModel(new DHKPTableModel(new Object[][]{
                    {"Loading..", "Loading..", "Loading..", "Loading..", "Loading..",
                        "Loading.."}}, header));
        showPB(ProgressBarSearch);

    }//GEN-LAST:event_NextBlockButtonMouseClicked

    private void LastBlockButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_LastBlockButtonMouseClicked
        if (!LastBlockButton.isEnabled()) {
            return;
        }
        SearchButton.setEnabled(false);
        FirstBlockButton.setEnabled(false);
        PreviousBlockButton.setEnabled(false);
        PreviousRowButton.setEnabled(false);
        NextRowButton.setEnabled(false);
        NextBlockButton.setEnabled(false);
        LastBlockButton.setEnabled(false);

        SwingWorker block = new SwingWorker<Object[][], Void>() {

            double Block;

            @Override
            public Object[][] doInBackground() {
                try {

                    Block = Double.parseDouble(dhkp.getQuery("select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'paging'").toString());
                    firstRecord = (int)(Block * Math.floor(totalRow / Block));

                    //Sudah pernah di filter
                    if (cb2.toString().contains("limit")) {
                        cb2.replace(cb2.indexOf("limit"), cb2.length(), "limit " + Block + " offset " + firstRecord);
                    } else {
                        cb2.append(" limit ").append(Block);
                    }
                    dataVector = dhkp.getData(cb2.toString());
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
                return dataVector;
            }

            @Override
            public void done() {
                try {
                    getTabelDHKP().setModel(new DHKPTableModel(get(), header));
                } catch (InterruptedException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ExecutionException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }

                getTabelDHKP().getSelectionModel().addSelectionInterval(0, 0);
                SelectRowLabel.setText("Row: " + (firstRecord + getTabelDHKP().getSelectedRow() + 1) + " of " + totalRow);
                SelectPageLabel.setText("Page: "+ (int)(firstRecord/Block+1)+" of "+ (int)Math.ceil(totalRow/Block));
                hidePB(ProgressBarSearch);
                SearchButton.setEnabled(true);
                FirstBlockButton.setEnabled(true);
                PreviousBlockButton.setEnabled(true);
                PreviousRowButton.setEnabled(true);
                NextRowButton.setEnabled(true);
                NextBlockButton.setEnabled(true);
                LastBlockButton.setEnabled(true);
            }
        };
        block.execute();
        getTabelDHKP().setModel(new DHKPTableModel(new Object[][]{
                    {"Loading..", "Loading..", "Loading..", "Loading..", "Loading..",
                        "Loading.."}}, header));

        showPB(ProgressBarSearch);
    }//GEN-LAST:event_LastBlockButtonMouseClicked

    private void PrintButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PrintButtonMouseClicked
        if (!PrintButton.isEnabled()) {
            return;
        }
        
        if(cb2.toString().contains("limit")){
            cb2.delete(cb2.toString().indexOf("limit"), cb2.length());
        }        
        
        if (ComboBoxPrint.getSelectedIndex() == -1) {
            JOptionPane.showMessageDialog(rootPane, "Pilih printer lebih dulu!!!", "Warning", JOptionPane.WARNING_MESSAGE);
        } else {
            if (getComboBoxKecamatan().getSelectedIndex() != -1 && getComboBoxKelurahan().getSelectedIndex() != -1 && !TfTahun.getText().equals("") && getComboBoxBuku().getSelectedIndex() != -1) {
                if (clickedSearch) {
                    try {
                        pd.setLocationRelativeTo(null);
                        pd.setVisible(true);
                    } catch (Exception ex) {
                        Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    JOptionPane.showMessageDialog(rootPane, "Klik tombol Search lebih dulu!!!", "Warning", JOptionPane.WARNING_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(rootPane, "Pilih Kecamatan, Kelurahan, Tahun, dan Buku lebih dulu!!!", "Warning", JOptionPane.WARNING_MESSAGE);
            }
        }
    }//GEN-LAST:event_PrintButtonMouseClicked

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened
        // TODO add your handling code here:
        SearchButton.setEnabled(false);
        
        SwingWorker tableinit = new SwingWorker<Object[][], Void>(){
            @Override
            public Object[][] doInBackground(){
                try {                        
                    dataVector = dhkp.getData(cb2.toString());                        
                } 
                catch (Exception ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                return dataVector;
            }

            @Override
            public void done(){
                try {
                    getTabelDHKP().setModel(new DHKPTableModel(get(), header));
                    hidePB(ProgressBarSearch);
                    SearchButton.setEnabled(true);   
                    FirstBlockButton.setEnabled(true);
                    LastBlockButton.setEnabled(true);
                    NextBlockButton.setEnabled(true);
                    PreviousBlockButton.setEnabled(true);
                    NextRowButton.setEnabled(true);
                    PreviousRowButton.setEnabled(true);
                    PrintButton.setEnabled(true);
                } 
                catch (InterruptedException ex) {                
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                } 
                catch (ExecutionException ex) {
                    Logger.getLogger(DHKPInternalFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        };
        tableinit.execute();
        showPB(ProgressBarSearch);        
    }//GEN-LAST:event_formInternalFrameOpened

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox ComboBoxBuku;
    private javax.swing.JComboBox ComboBoxKecamatan;
    private javax.swing.JComboBox ComboBoxKelurahan;
    private javax.swing.JComboBox ComboBoxPrint;
    private javax.swing.JButton FirstBlockButton;
    private javax.swing.JButton LastBlockButton;
    private javax.swing.JButton NextBlockButton;
    private javax.swing.JButton NextRowButton;
    private javax.swing.JButton PreviousBlockButton;
    private javax.swing.JButton PreviousRowButton;
    private javax.swing.JButton PrintButton;
    private javax.swing.JProgressBar ProgressBarSearch;
    private javax.swing.JScrollPane ScrollPane;
    private javax.swing.JButton SearchButton;
    private javax.swing.JLabel SelectPageLabel;
    private javax.swing.JPanel SelectPagePanel;
    private javax.swing.JLabel SelectRowLabel;
    private javax.swing.JPanel SelectRowPanel;
    private javax.swing.JTable TabelDHKP;
    private javax.swing.JTextField TfBlok;
    private javax.swing.JTextField TfNOP;
    private javax.swing.JTextField TfNama;
    private javax.swing.JTextField TfTahun;
    private javax.swing.JTextField TfUrutDari;
    private javax.swing.JTextField TfUrutSampai;
    private javax.swing.JToolBar ToolBar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
    
    
//    //Fungsi untuk nge-print
    public void PrintAllPage() throws Exception {
        String[][] data= new String[totalRow][14];
        data = dhkp.getPrintData(cb2.toString());
        System.out.println("printall"+cb2.toString());
        if(!ComboBoxPrint.getSelectedItem().toString().equals("")){
            pt.setPrint(ComboBoxPrint.getSelectedItem().toString());      
            pt.printAll(mf, data,plog.getProgressBarPrint(),plog);
            plog.setLocationRelativeTo(null);
            plog.setVisible(true);  
        }
    }
    public void PrintOnePage() throws Exception{
        String[][] data= new String[totalRow][14];
        data = dhkp.getPrintData(cb2.toString());

        if(!ComboBoxPrint.getSelectedItem().toString().equals("")){
            pt.setPrint(ComboBoxPrint.getSelectedItem().toString());
            pt.printOnePage(pd,mf,data,plog.getProgressBarPrint(),plog);
            plog.setLocationRelativeTo(null);
            plog.setVisible(true);
        }
    }
    public void PrintCustomPage() throws Exception{
        String[][] data= new String[totalRow][14];
        data = dhkp.getPrintData(cb2.toString());

        if(!ComboBoxPrint.getSelectedItem().toString().equals("")){
            pt.setPrint(ComboBoxPrint.getSelectedItem().toString());
            pt.printCustomPage(pd,mf, data,plog.getProgressBarPrint(),plog);
            plog.setLocationRelativeTo(null);
            plog.setVisible(true);
        }
    }
    public void PrintCover() throws Exception{
        String[][] data= new String[totalRow][14];        
        data = dhkp.getPrintData(cb2.toString());

        if(!ComboBoxPrint.getSelectedItem().toString().equals("")){
            pt.setPrint(ComboBoxPrint.getSelectedItem().toString());
            pt.printRealFirstPage(mf, data,plog.getProgressBarPrint(),plog);
            plog.setLocationRelativeTo(null);
            plog.setVisible(true);
        }
    }
    public void PrintKetetapan() throws Exception{
        String[][] data= new String[totalRow][14];
        data = dhkp.getPrintData(cb2.toString());

        if(!ComboBoxPrint.getSelectedItem().toString().equals("")){
            pt.setPrint(ComboBoxPrint.getSelectedItem().toString());
            pt.printRealLastPage(mf, data,plog.getProgressBarPrint(),plog);
            plog.setLocationRelativeTo(null);
            plog.setVisible(true);
        }  
    }
    public int noHal() throws Exception{
        int nohal;
        
        String[][] data= new String[totalRow][14];
        data = dhkp.getPrintData(cb2.toString());
        pt.setPrint(ComboBoxPrint.getSelectedItem().toString());
        nohal = pt.getNoHalaman(data);
        return nohal;
    }
    public void PrintFromFirstPage() throws Exception{
        String[][] data= new String[totalRow][14];
        data = dhkp.getPrintData(cb2.toString());

        if(!ComboBoxPrint.getSelectedItem().toString().equals("")){
            pt.setPrint(ComboBoxPrint.getSelectedItem().toString());
            pt.printFromFirstPage(pd, mf, data,plog.getProgressBarPrint(),plog);
            plog.setLocationRelativeTo(null);
            plog.setVisible(true);
        }  
    }
    public void PrintToLastPage() throws Exception{
        String[][] data= new String[totalRow][14];
        data = dhkp.getPrintData(cb2.toString());

        if(!ComboBoxPrint.getSelectedItem().toString().equals("")){
            pt.setPrint(ComboBoxPrint.getSelectedItem().toString());
            pt.printToLastPage(pd, mf, data,plog.getProgressBarPrint(),plog);
            plog.setLocationRelativeTo(null);
            plog.setVisible(true);
        }  
    }
    public void showPB(JProgressBar pb){       
        pb.setValue(0);
        pb.setVisible(true); 
        pb.setIndeterminate(true);
        pb.setStringPainted(false);        
    }
    
    public void hidePB(JProgressBar pb){
        pb.setIndeterminate(false);            
        pb.setStringPainted(true);
        pb.setVisible(false);                     
    }
    public void doSearch(){
        String Kel = null;
        if(getComboBoxKelurahan().getSelectedIndex()!=-1){
            Kel = getComboBoxKelurahan().getSelectedItem().toString();
        }        

        if(Kel == null || Kel.trim().equals("")||Kel.trim().substring(6).equals("-")){
            JOptionPane.showMessageDialog(rootPane, "Ubah Kelurahan sebelum memulai pencarian!!!", "Warning", JOptionPane.WARNING_MESSAGE);
            clickedSearch = false;  
            Thread.currentThread().interrupt();
        }
        
        String snobuku = null;
        int nobuku = 0;
        if(getComboBoxBuku().getSelectedIndex()!=-1){
            snobuku = getComboBoxBuku().getSelectedItem().toString();
        }
        if(snobuku != null){            
            Matcher m = p.matcher(snobuku);
            while(m.find()){
                nobuku = Integer.parseInt(m.group());  
            }
        }
        cb.setLength(0);
        cb2.setLength(0);
        
        cb.append("select count(*) from pbb.view_sppt");
        cb2.append("select * from pbb.view_sppt");
        
        /*
         * Inisialisasi penampung cKec & cKel
         */
        String Kec = null;

        if(getComboBoxKecamatan().getSelectedIndex()!=-1){
            Kec = getComboBoxKecamatan().getSelectedItem().toString();
        }
        
        if(Kec != null ||
            !TfNOP.getText().trim().equals("") ||
            !TfNama.getText().toUpperCase().trim().equals("") ||
            !TfBlok.getText().trim().equals("") ||
            (!TfUrutDari.getText().trim().equals("") && !TfUrutSampai.getText().trim().equals("")) ||
            !TfTahun.getText().trim().equals("") ||                
            nobuku!=0){
            cb.append(" where");
            cb2.append(" where");
        }
        if(Kec != null){
            cb.append(" substring (pbb.view_sppt.nop from 1 for 10) = " 
                    + "(select pbb.pbb_master_kelurahan.kode_kelurahan " 
                    + "from pbb.pbb_master_kelurahan " 
                    + "where " 
                        + "(substring(pbb.pbb_master_kelurahan.kode_kelurahan from 1 for 7) " 
                        + "= (select pbb.pbb_master_kecamatan.kode_kecamatan from pbb.pbb_master_kecamatan where " 
                            + "(substring(pbb.pbb_master_kecamatan.kode_kecamatan from 1 for 4) = (select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'kode_kota') " 
                            + "and pbb.pbb_master_kecamatan.nama_kecamatan = '").append(Kec.trim().substring(6)).append("')) " 
                    + "and pbb.pbb_master_kelurahan.nama_kelurahan = '").append(Kel.trim().substring(6)).append("'))");
            
            cb2.append(" substring (pbb.view_sppt.nop from 1 for 10) = " 
                    + "(select pbb.pbb_master_kelurahan.kode_kelurahan " 
                    + "from pbb.pbb_master_kelurahan " 
                    + "where " 
                        + "(substring(pbb.pbb_master_kelurahan.kode_kelurahan from 1 for 7) " 
                        + "= (select pbb.pbb_master_kecamatan.kode_kecamatan from pbb.pbb_master_kecamatan where " 
                            + "(substring(pbb.pbb_master_kecamatan.kode_kecamatan from 1 for 4) = (select pbb.pbb_setting.value from pbb.pbb_setting where pbb.pbb_setting.setting = 'kode_kota') " 
                            + "and pbb.pbb_master_kecamatan.nama_kecamatan = '").append(Kec.trim().substring(6)).append("')) " 
                    + "and pbb.pbb_master_kelurahan.nama_kelurahan = '").append(Kel.trim().substring(6)).append("'))");
            
            if(!TfNOP.getText().trim().equals("") ||
                !TfNama.getText().toUpperCase().trim().equals("") ||
                !TfBlok.getText().trim().equals("") ||
                (!TfUrutDari.getText().trim().equals("") && !TfUrutSampai.getText().trim().equals("")) ||
                !TfTahun.getText().trim().equals("") ||    
                nobuku!=0){
                cb.append(" and");
                cb2.append(" and");
            }            
        }
        
        //NOP
        if(!TfNOP.getText().trim().equals("")){
            cb.append(" nop = '").append(TfNOP.getText().trim()).append("'");
            cb2.append(" nop = '").append(TfNOP.getText().trim()).append("'");
            
            if(!TfNama.getText().toUpperCase().trim().equals("") ||
            !TfBlok.getText().trim().equals("") ||
            (!TfUrutDari.getText().trim().equals("") && !TfUrutSampai.getText().trim().equals("")) ||    
            !TfTahun.getText().trim().equals("") ||                        
            nobuku!=0){
                cb.append(" and");
                cb2.append(" and");
            }
        }
        
        //Nama
        if(!TfNama.getText().toUpperCase().trim().equals("")){
            cb.append(" wp_nama like '%").append(TfNama.getText().toUpperCase().trim()).append("%'");
            cb2.append(" wp_nama like '%").append(TfNama.getText().toUpperCase().trim()).append("%'");
            
            if(!TfBlok.getText().trim().equals("") ||
            (!TfUrutDari.getText().trim().equals("") && !TfUrutSampai.getText().trim().equals("")) ||
            !TfTahun.getText().trim().equals("") ||                        
            nobuku!=0){
                cb.append(" and");
                cb2.append(" and");
            }            
        }   
        
        //Blok
        if(!TfBlok.getText().trim().equals("")){
            cb.append(" substr(nop,11,3) = '").append(TfBlok.getText().trim()).append("'");
            cb2.append(" substr(nop,11,3) = '").append(TfBlok.getText().trim()).append("'");
            
            if((!TfUrutDari.getText().trim().equals("") && !TfUrutSampai.getText().trim().equals("")) ||
            !TfTahun.getText().trim().equals("") ||                        
            nobuku!=0){
                cb.append(" and");
                cb2.append(" and");
            }
        }
        
        //No urut
        if(!TfUrutDari.getText().trim().equals("") && !TfUrutSampai.getText().trim().equals("")){
            cb.append(" cast(substr(nop,14,4) as integer) between ").append(TfUrutDari.getText().trim()).append(" and ").append(TfUrutSampai.getText().trim());
            cb2.append(" cast(substr(nop,14,4) as integer) between ").append(TfUrutDari.getText().trim()).append(" and ").append(TfUrutSampai.getText().trim());
            
            if(!TfTahun.getText().trim().equals("") ||    
            nobuku!=0){
                cb.append(" and");
                cb2.append(" and");
            }
        }
        
        //Tahun
         if(!TfTahun.getText().trim().equals("")){
            cb.append(" sppt_tahun_pajak = '").append(getTfTahun().getText().trim()).append("'");
            cb2.append(" sppt_tahun_pajak = '").append(getTfTahun().getText().trim()).append("'");
            
            if(nobuku!=0){
                cb.append(" and");
                cb2.append(" and");
            }
        }
        //Buku
        if(nobuku!=0){
            cb.append(" buku = ").append(nobuku);
            cb2.append(" buku = ").append(nobuku);
        }                 
    }

    /**
     * @return the ComboBoxKecamatan
     */
    public javax.swing.JComboBox getComboBoxKecamatan() {
        return ComboBoxKecamatan;
    }

    /**
     * @return the ComboBoxKelurahan
     */
    public javax.swing.JComboBox getComboBoxKelurahan() {
        return ComboBoxKelurahan;
    }

    /**
     * @return the TfTahun
     */
    public javax.swing.JTextField getTfTahun() {
        return TfTahun;
    }

    /**
     * @return the TabelDHKP
     */
    public javax.swing.JTable getTabelDHKP() {
        return TabelDHKP;
    }

    /**
     * @return the ComboBoxBuku
     */
    public javax.swing.JComboBox getComboBoxBuku() {
        return ComboBoxBuku;
    }
}
